package com.effort.com.effort.excle.controller;

import com.effort.com.effort.excle.core.util.ServletUtils;
import com.effort.com.effort.excle.query.BaseQuery;
import com.effort.com.effort.excle.service.ExcleService;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class ExcleController {

    @Resource
    private ExcleService excleService;

    /**
     *  处理导出
     */
    @PostMapping("excle")
    public void excle(@RequestBody  BaseQuery query) throws Exception {
        Workbook excle = this.excleService.excle(query);
        ServletUtils.getResponse().setContentType("application/vnd.ms-excel");
        ServletUtils.getResponse().setHeader("Content-disposition", "attachment;filename="
                + 123+".xls");
        excle.write(ServletUtils.getResponse().getOutputStream());
        ServletUtils.getResponse().getOutputStream().flush();
        ServletUtils.getResponse().getOutputStream().close();
    }




}
